<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns:d="http://dyomedea.com/ns/id">
  <define name="topLevel" d:id="ch16-top-level">
    <zeroOrMore>
      <ref name="decl"/>
    </zeroOrMore>
    <choice>
      <ref name="pattern"/>
      <zeroOrMore>
        <ref name="grammarContent"/>
      </zeroOrMore>
    </choice>
  </define>
  <define name="decl" d:id="ch16-decl">
    <choice>
      <group d:id="ch16-namespace">
        <value>namespace</value>
        <ref name="identifierOrKeyword"/>
        <value>=</value>
        <ref name="namespaceURILiteral"/>
      </group>
      <group  d:id="ch16-default-namespace">
        <value>default</value>
        <value>namespace</value>
        <optional>
          <ref name="identifierOrKeyword"/>
        </optional>
        <value>=</value>
        <ref name="namespaceURILiteral"/>
      </group>
      <group d:id="ch16-datatypes">
        <value>datatypes</value>
        <ref name="identifierOrKeyword"/>
        <value>=</value>
        <ref name="literal"/>
      </group>
    </choice>
  </define>
  <define name="pattern" d:id="ch16-pattern">
    <choice>
      <group d:id="ch15-element">
        <value>element</value>
        <ref name="nameClass"/>
        <value>{</value>
        <ref name="pattern"/>
        <value>}</value>
      </group>
      <group d:id="ch15-attribute">
        <value>attribute</value>
        <ref name="nameClass"/>
        <value>{</value>
        <ref name="pattern"/>
        <value>}</value>
      </group>
      <group d:id="ch15-group">
        <ref name="pattern"/>
        <oneOrMore>
          <value>,</value>
          <ref name="pattern"/>
        </oneOrMore>
      </group>
      <group d:id="ch15-interleave">
        <ref name="pattern"/>
        <oneOrMore>
          <value>&amp;</value>
          <ref name="pattern"/>
        </oneOrMore>
      </group>
      <group d:id="ch15-choice1">
        <ref name="pattern"/>
        <oneOrMore>
          <value>|</value>
          <ref name="pattern"/>
        </oneOrMore>
      </group>
      <group d:id="ch15-optional">
        <ref name="pattern"/>
        <value>?</value>
      </group>
      <group d:id="ch15-zeroOrMore">
        <ref name="pattern"/>
        <value>*</value>
      </group>
      <group d:id="ch15-oneOrMore">
        <ref name="pattern"/>
        <value>+</value>
      </group>
      <group d:id="ch15-list">
        <value>list</value>
        <value>{</value>
        <ref name="pattern"/>
        <value>}</value>
      </group>
      <group d:id="ch15-mixed">
        <value>mixed</value>
        <value>{</value>
        <ref name="pattern"/>
        <value>}</value>
      </group>
      <ref name="identifier"/>
      <group d:id="ch15-parentRef">
        <value>parent</value>
        <ref name="identifier"/>
      </group>
      <value d:id="ch15-empty">empty</value>
      <value d:id="ch15-text">text</value>
      <group d:id="ch15-value">
        <optional>
          <ref name="datatypeName"/>
        </optional>
        <ref name="literal"/>
      </group>
      <group d:id="ch15-data">
        <ref name="datatypeName"/>
        <optional>
          <value>{</value>
          <zeroOrMore>
            <ref name="param"/>
          </zeroOrMore>
          <value>}</value>
        </optional>
        <optional>
          <ref name="exceptPattern"/>
        </optional>
      </group>
      <value d:id="ch15-notAllowed">notAllowed</value>
      <group d:id="ch15-externalRef">
        <value>external</value>
        <ref name="literal"/>
        <optional>
          <ref name="inherit"/>
        </optional>
      </group>
      <group d:id="ch15-grammar">
        <value>grammar</value>
        <value>{</value>
        <zeroOrMore>
          <ref name="grammarContent"/>
        </zeroOrMore>
        <value>}</value>
      </group>
      <group d:id="ch16-parenthesis">
        <value>(</value>
        <ref name="pattern"/>
        <value>)</value>
      </group>
    </choice>
  </define>
  <define name="param" d:id="ch15-param">
    <ref name="identifierOrKeyword"/>
    <value>=</value>
    <ref name="literal"/>
  </define>
  <define name="exceptPattern" d:id="ch15-except1">
    <value>-</value>
    <ref name="pattern"/>
  </define>
  <define name="grammarContent" d:id="ch16-grammarContent">
    <choice>
      <ref name="start"/>
      <ref name="define"/>
      <group d:id="ch15-div1">
        <value>div</value>
        <value>{</value>
        <zeroOrMore>
          <ref name="grammarContent"/>
        </zeroOrMore>
        <value>}</value>
      </group>
      <group d:id="ch15-include">
        <value>include</value>
        <ref name="literal"/>
        <optional>
          <ref name="inherit"/>
        </optional>
        <optional>
          <value>{</value>
          <zeroOrMore>
            <ref name="includeContent"/>
          </zeroOrMore>
          <value>}</value>
        </optional>
      </group>
    </choice>
  </define>
  <define name="includeContent" d:id="ch16-includeContent">
    <choice>
      <ref name="define"/>
      <ref name="start"/>
      <group>
        <value>div</value>
        <value>{</value>
        <zeroOrMore>
          <ref name="includeContent"/>
        </zeroOrMore>
        <value>}</value>
      </group>
    </choice>
  </define>
  <define name="start" d:id="ch15-start">
    <value>start</value>
    <ref name="assignMethod"/>
    <ref name="pattern"/>
  </define>
  <define name="define" d:id="ch15-define">
    <ref name="identifier"/>
    <ref name="assignMethod"/>
    <ref name="pattern"/>
  </define>
  <define name="assignMethod" d:id="ch16-assignMethod">
    <choice>
      <value>=</value>
      <value>|=</value>
      <value>&amp;=</value>
    </choice>
  </define>
  <define name="nameClass" d:id="ch16-nameClass">
    <choice>
      <ref name="name"/>
      <group d:id="ch15-nsName">
	<data type="NCName"/>
    	<value>:*</value>
        <optional>
          <ref name="exceptNameClass"/>
        </optional>
      </group>
      <group d:id="ch15-anyName">
	<value>*</value>
        <optional>
          <ref name="exceptNameClass"/>
        </optional>
      </group>
      <group d:id="ch15-choice2">
        <ref name="nameClass"/>
        <value>|</value>
        <ref name="nameClass"/>
      </group>
      <group d:id="ch16-parenthesis-nc">
        <value>(</value>
        <ref name="nameClass"/>
        <value>)</value>
      </group>
    </choice>
  </define>
  <define name="name" d:id="ch16-name">
    <choice>
      <ref name="identifierOrKeyword"/>
      <ref name="CName"/>
    </choice>
  </define>
  <define name="exceptNameClass" d:id="ch15-except2">
    <value>-</value>
    <ref name="nameClass"/>
  </define>
  <define name="datatypeName" d:id="ch16-datatypeName">
    <choice>
      <ref name="CName"/>
      <value>string</value>
      <value>token</value>
    </choice>
  </define>
  <define name="namespaceURILiteral" d:id="namespaceURILiteral">
    <choice>
      <ref name="literal"/>
      <value>inherit</value>
    </choice>
  </define>
  <define name="inherit" d:id="inherit">
    <value>inherit</value>
    <value>=</value>
    <ref name="identifierOrKeyword"/>
  </define>
  <define name="identifierOrKeyword" d:id="identifierOrKeyword">
    <choice>
      <ref name="identifier"/>
      <ref name="keyword"/>
    </choice>
  </define>
  <define name="identifier" d:id="identifier">
    <choice>
      <data type="NCName">
        <except>
          <ref name="keyword"/>
        </except>
      </data>
      <ref name="quotedIdentifier"/>
    </choice>
  </define>
  <define name="quotedIdentifier" d:id="quotedIdentifier">
    <value>\</value>
    <data type="NCName"/>
  </define>
  <define name="CName" d:id="CName">
    <data type="NCName"/>
    <value>:</value>
    <data type="NCName"/>
  </define>
  <define name="literal" d:id="literal">
    <ref name="literalSegment"/>
    <oneOrMore>
      <value>~</value>
      <ref name="literalSegment"/>
    </oneOrMore>
  </define>
  <define name="literalSegment" d:id="literalSegment">
    <choice>
      <group d:id="literalSegmentDoubleQuote">
        <value>"</value>
        <zeroOrMore>
          <data type="Char" datatypeLibrary="http://www.thaiopensource.com/relaxng/compact/datatypes">
            <except>
              <value>"</value>
              <data type="newline" datatypeLibrary="http://www.thaiopensource.com/relaxng/compact/datatypes"/>
            </except>
          </data>
        </zeroOrMore>
        <value>"</value>
      </group>
      <group d:id="literalSegmentSimpleQuote">
        <value>'</value>
        <zeroOrMore>
          <data type="Char" datatypeLibrary="http://www.thaiopensource.com/relaxng/compact/datatypes">
            <except>
              <value>'</value>
              <data type="newline" datatypeLibrary="http://www.thaiopensource.com/relaxng/compact/datatypes"/>
            </except>
          </data>
        </zeroOrMore>
        <value>'</value>
      </group>
      <group d:id="literalSegmentPythonicDouble">
        <value>"""</value>
        <zeroOrMore>
          <optional>
            <value>"</value>
          </optional>
          <optional>
            <value>"</value>
          </optional>
          <data type="Char" datatypeLibrary="http://www.thaiopensource.com/relaxng/compact/datatypes">
            <except>
              <value>"</value>
            </except>
          </data>
        </zeroOrMore>
        <value>"""</value>
      </group>
      <group d:id="literalSegmentPythonicSimple">
        <value>'''</value>
        <zeroOrMore>
          <optional>
            <value>'</value>
          </optional>
          <optional>
            <value>'</value>
          </optional>
          <data type="Char" datatypeLibrary="http://www.thaiopensource.com/relaxng/compact/datatypes">
            <except>
              <value>'</value>
            </except>
          </data>
        </zeroOrMore>
        <value>'''</value>
      </group>
    </choice>
  </define>
  <define name="keyword" d:id="keyword">
    <choice>
      <value>attribute</value>
      <value>default</value>
      <value>datatypes</value>
      <value>div</value>
      <value>element</value>
      <value>empty</value>
      <value>external</value>
      <value>grammar</value>
      <value>include</value>
      <value>inherit</value>
      <value>list</value>
      <value>mixed</value>
      <value>namespace</value>
      <value>notAllowed</value>
      <value>parent</value>
      <value>start</value>
      <value>string</value>
      <value>text</value>
      <value>token</value>
    </choice>
  </define>
</grammar>
